package org.flexthinker.binding.value.support
{

    import org.flexthinker.binding.conversion.support.PropertyConverter;
    import org.hamcrest.assertThat;
    import org.hamcrest.object.equalTo;

    public class TypeConverterTest
    {

        private var bean:MockBean;
        private var tc:TypeConverter;


        public function TypeConverterTest()
        {
        }

        [Before]
        public function setUp():void
        {
            bean = new MockBean();
            bean.objectHolder = new MockBean();
            bean.simpleString = "AAA";
            bean.simpleNumber = 123;

            tc = new TypeConverter(new ValueHolder(bean, "simpleString"),
                    new PropertyConverter(
                            function convertForward(value:String):String
                            {
                                return value + ".";
                            },
                            function convertReverse(value:String):String
                            {
                                return "." + value;
                            }
                            ));
        }

        [Test]
        public function testGetValue():void
        {
            assertThat(tc.getValue(), equalTo("." + bean.simpleString ));
            // also test that calling getValue twice will still have the same result
            assertThat(tc.getValue(), equalTo("." + bean.simpleString ));

        }

        [Test]
        public function testSetValue():void
        {
            tc.setValue( "XYZ" );
            assertThat(bean.simpleString, equalTo("XYZ."));
            assertThat(tc.getValue(), equalTo(".XYZ."));
            // also test that calling getValue twice will still have the same result
            assertThat( tc.getValue(), equalTo(".XYZ."));
        }
    }
}
